package com.dmzc.stage2.chapter14;

import java.net.Socket;
import java.sql.Connection;

/***
 * 懒汉式 double check   volatile解决double check问题
 * 能够实现懒加载,线程安全，但是效率低下
 */
public final class Singleton4 {
    private byte[] data = new byte[1024];
    Connection connection;
    Socket socket;
    private static volatile Singleton4 instance = null;

    private Singleton4() {
        this.connection = null;
        this.socket = null;

    }

    public static Singleton4 getInstance() {
        if (null == instance){
            synchronized (Singleton4.class){
                if (null==instance){
                    instance=new Singleton4();
                }
            }
        }
        return instance;
    }
}
